package daily.may0528;

public class TicketRunnableTest {
    public static void main(String[] args) {
        //匿名内部类
        Runnable tw = new Runnable() {
            int tickets = 10;//共10张票
            @Override
            public void run() {
                while(tickets>0) {
                    System.out.printf("%s窗口第%d张票已经售出\n", Thread.currentThread().getName(), tickets--);
                }
            }
        };
//        //也可以写Lambda表达式
//        Runnable tw = ()->{
//            int tickets = 10;//共10张票
//                while(tickets>0) {
//                    System.out.printf("%s窗口第%d张票已经售出\n", Thread.currentThread().getName(), tickets--);
//                }
//            };
        new Thread(tw, "窗口1").start();
        new Thread(tw, "窗口2").start();
        new Thread(tw, "窗口3").start();
        new Thread(tw, "窗口4").start();
    }
}
